import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.temporal.ChronoUnit;
import java.util.Locale;

/**
 * @version : V1.0
 * @program: maven
 * @ClassName: D5
 * @Description:
 * @Author: chenxiejia
 * @Date: 2022/2/10 19:20
 */
public class D5 {
    public static void main(String[] args) {
        var dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        LocalDateTime ldt = LocalDateTime.parse("2020-01-25 12:45:56", dtf);
        //var t = ldt.format(dtf);
        LocalDateTime ldt1 = LocalDateTime.now();
        System.out.println(ldt.getYear());
        System.out.println(ldt.getMonth().getDisplayName(TextStyle.FULL, Locale.CHINA));
        //换算成秒需要设置时区
        System.out.println(ldt.toEpochSecond(ZoneOffset.of("+8")));
        //获取当前时间的毫秒
        System.out.println(ldt1.toInstant(ZoneOffset.of("+8")).toEpochMilli());

        //LocalDateTime转换成LocalDate
        System.out.println(ldt.toLocalDate().getYear());
        System.out.println(ldt.toLocalDate().getDayOfMonth());
        System.out.println(ldt.toLocalDate().getMonth());
        //LocalDateTime转换成LocalTime
        System.out.println(ldt.toLocalTime().getHour());
        System.out.println(ldt.toLocalTime().getMinute());
        System.out.println(ldt.toLocalTime().getSecond());
        //计算两个时间的差值

        //方式1
        System.out.println(ldt.until(ldt1, ChronoUnit.DAYS));
        //方式2
        System.out.println(Duration.between(ldt, ldt1).toDays());
        //方式3
        System.out.println(ChronoUnit.DAYS.between(ldt, ldt1));

    }
}
